package com.ldy.chat.server;

import com.ldy.chat.service.ChatServerService;
import com.ldy.chat.service.impl.ChatServerServiceImpl;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.server.TNonblockingServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.layered.TFastFramedTransport;

/**
 * 聊天的服务器
 * @Auther lin DeYU
 * @Date 2021/3/30
 */
public class ChatServer  {

    private int PORT=9000;

    // 获取构建聊天服务端服务器
    public TNonblockingServer getTNonblockingServer() throws TTransportException {
        // 设置通信监听端口
        TNonblockingServerSocket tNonblockingServerSocket=new TNonblockingServerSocket(this.PORT);
        ChatServerService.Processor processor =
                new ChatServerService.Processor<ChatServerService.Iface>(new ChatServerServiceImpl());
        // 数据序列化的方式
        TJSONProtocol.Factory protocolFactory = new   TJSONProtocol.Factory();
        TNonblockingServer.Args targs=new TNonblockingServer.Args(tNonblockingServerSocket);
        //设置远程调用的过程
        targs.processor(processor);
        // 传输数据序列化的协议
        targs.protocolFactory(protocolFactory);
        //设置数据传输的方式
        targs.transportFactory(new TFastFramedTransport.Factory());
        return new TNonblockingServer(targs);
    }

}
